package cn.zbmao.web.dao;

import cn.zbmao.web.bean.Constants;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

import java.util.List;

/**
 * Created by 愤怒的番茄 on 2014/10/8.
 */
public class QualificationDao {
    /**
     *
     * @return
     * 查询已经通过审核的资质，并且key对应name
     */
    public List<Record> findQualificationList(){
        return Db.find("SELECT id,`name`,`key` FROM " + Constants.QUALIFICATION + " WHERE is_ok=1 and is_key=1");
                                                     //qualification
    }

    /**
     *
     * @param name 资质名称
     * @return
     * 通过资质名称查询资质
     */
    public List<Record> findQualificationOther(String name){
    	return Db.find("SELECT id,`name`,`key` FROM " + Constants.QUALIFICATION + " WHERE is_key=2 and name=?", name);
                                                    //qualification
    }

    /**
     *
     * @param name 资质名称
     * @return
     * 通过资质名称查询资质
     */
    public List<Record> findQualifcationName(String name){
        return Db.find("select * from " + Constants.QUALIFICATION + " where name = ? and is_key=1", name);
                                                 //qualification
    }

    /**
     *
     * @param record 保存的资质信息
     * @return
     * 向资质表中存入一条数据
     */
    public Record add(Record record){
        Db.save("qualification", record);
        return record;
    }

}
